﻿<Window x:Class="Graphviz4Net.WPF.Example.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:i="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:Controls="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions" 
        xmlns:Example="clr-namespace:Graphviz4Net.WPF.Example" 
        xmlns:WPF="clr-namespace:Graphviz4Net.WPF;assembly=Graphviz4Net.WPF" 
        xmlns:ViewModels="clr-namespace:Graphviz4Net.WPF.ViewModels;assembly=Graphviz4Net.WPF" 
        Title="Contacts visualization with Graphiz4Net and WPF" 
        Height="{Binding WindowHeight, Mode=OneWayToSource}" 
        Width="{Binding WindowWidth, Mode=OneWayToSource}">
    <Window.Resources>
        <DataTemplate DataType="{x:Type Example:Person}">
            <Border BorderBrush="Black" BorderThickness="1" Padding="0" CornerRadius="5" Background="White">
                <Border.Style>
                    <Style>
                        <Style.Triggers>
                            <Trigger Property="Border.IsMouseOver" Value="True">
                                <Setter Property="Border.Effect">
                                    <Setter.Value>
                                        <DropShadowEffect BlurRadius="2" Color="#BBBBBB" 
		                                                    Opacity="0.3" Direction="315"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Border.Style>             
                <StackPanel Orientation="Horizontal">
                    <Image Source="{Binding Avatar}" Width="32" Height="32" Margin="5" VerticalAlignment="Top"/>
                    <StackPanel Orientation="Vertical" Margin="2">
                        <TextBlock Text="{Binding Name}"/>
                        <TextBlock Text="{Binding Email}"/>
                        <Separator Margin="0, 5, 0, 5"/>

                        <TextBlock><Underline>Send a Message</Underline></TextBlock>
                        <Button Command="{Binding RemoveCommand}">
                            <Button.Template>
                                <ControlTemplate>
                                    <TextBlock><Underline>Remove</Underline></TextBlock>
                                </ControlTemplate>
                            </Button.Template>                            
                        </Button>
                    </StackPanel>
                </StackPanel>
            </Border>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type Example:DiamondArrow}">
            <Canvas Width="6" Height="11">
                <Polygon Points="3,0 6,5 3,10 0,5" Stroke="Black" StrokeThickness="1" Fill="Black"/>
            </Canvas>            
        </DataTemplate>

        <DataTemplate DataType="{x:Type Example:Arrow}">
            <Path Data="M 0,0 L 20,0 L 10,10 L 0,0" Stroke="Black" StrokeThickness="1">
            </Path>
        </DataTemplate>        

        <!-- Set UseContentPresenterForAllElements of GraphLayout to true -->
        <DataTemplate DataType="{x:Type ViewModels:EdgeLabelViewModel}">
            <StackPanel>
                <TextBlock Text="{Binding Path=Label}" FontFamily="Comic Sans MS"/>
            </StackPanel>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:BorderViewModel}">
            <Border BorderBrush="Green"
                    BorderThickness="2"
                    CornerRadius="10"
                    Padding="10, 0, 0, 0">
                <TextBlock Text="{Binding Path=Label}" FontStyle="Italic"/>
            </Border>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:EdgeArrowLabelViewModel}">
            <TextBlock Text="{Binding Path=Label}" Background="White"/>
        </DataTemplate>

        <DataTemplate DataType="{x:Type ViewModels:EdgeViewModel}">
            <Path Data="{Binding Data}" Stroke="Black" StrokeThickness="1" ToolTip="{Binding Edge.Label}"/>
        </DataTemplate>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="0" Background="#EEEEEE" Margin="0, 0, 0, 15">
            <StackPanel Margin="50, 10, 10, 10">
				<TextBlock FontSize="14" Margin="0, 0, 0 , 10">Add a new vertex:</TextBlock>
                <TextBox Text="{Binding NewPersonName}" Width="150" Margin="0, 0, 0, 10"/>
                <Button x:Name="AddNewPerson">Add new person</Button>
            </StackPanel>

            <StackPanel Margin="50, 10, 10, 10">
				<TextBlock FontSize="14" Margin="0, 0, 0 , 10">Add a new edge:</TextBlock>
				<StackPanel Orientation="Horizontal" Margin="0, 0, 0, 10">
                    <ComboBox x:Name="NewEdgeStart" ItemsSource="{Binding PersonNames}" Margin="0, 0, 10, 0" Width="100"/>
                    <ComboBox x:Name="NewEdgeEnd" ItemsSource="{Binding PersonNames}" Width="100"/>
                </StackPanel>
                <Grid Margin="0, 0, 0, 10">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Label Grid.Row="0" Grid.Column="0">Label: </Label>
                    <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding NewEdgeLabel}"></TextBox>
                </Grid>
                <Button x:Name="AddNewEdge">Add new link</Button>
            </StackPanel>
			
			<StackPanel Margin="75, 10, 0, 10" Width="200">
				<TextBlock FontSize="14" Margin="0, 0, 0 , 10">Update a person: </TextBlock>
				<ComboBox x:Name="UpdatePersonName" ItemsSource="{Binding PersonNames}" Margin="0, 0, 0 , 10"/>
				<Grid Margin="0, 0, 0, 10">
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="Auto"/>
						<ColumnDefinition Width="*"/>
					</Grid.ColumnDefinitions>
					<Label Grid.Row="0" Grid.Column="0">New name:</Label>
					<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding UpdatePersonNewName}"></TextBox>
				</Grid>
				<Button Margin="0, 0, 0, 10" x:Name="UpdatePerson">Update</Button>
			</StackPanel>
        </StackPanel>
        
        <Controls:ZoomControl Grid.Column="0" Grid.Row="1">
            <WPF:GraphLayout 
                UseContentPresenterForAllElements="True"
                LogGraphvizOutput="True"
                Graph="{Binding Graph}"
                x:Name="GraphLayout">
                <WPF:GraphLayout.Resources>
                    <Style TargetType="ProgressBar">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ProgressBar">
                                    <TextBlock Foreground="Black">Generating the layout...</TextBlock>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </WPF:GraphLayout.Resources>
            </WPF:GraphLayout>
        </Controls:ZoomControl>
    </Grid>
</Window>
